﻿/* VALIDACAO */

/*
 * jQuery Tooltip plugin 1.2
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 *
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *
 * $Id: jquery.tooltip.js 4569 2008-01-31 19:36:35Z joern.zaefferer $
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';(3($){m d={},k,g,w,S=$.2f.21&&/1Y\\s(5\\.5|6\\.)/.1B(1w.2e),H=1h;$.f={r:1h,1b:{O:1Q,11:Z,U:"",u:15,z:15,R:"f"},1t:3(){$.f.r=!$.f.r}};$.F.1o({f:3(a){a=$.1o({},$.f.1b,a);1j(a);e 2.B(3(){$.1d(2,"f-7",a);2.T=2.g;$(2).1W("g");2.1U=""}).1S(16,l).1O(l)},D:S?3(){e 2.B(3(){m b=$(2).o(\'N\');4(b.1G(/^j\\(["\']?(.*\\.1C)["\']?\\)$/i)){b=1y.$1;$(2).o({\'N\':\'1x\',\'17\':"1u:1s.1r.2c(2b=Z, 2a=29, 1k=\'"+b+"\')"}).B(3(){m a=$(2).o(\'1m\');4(a!=\'23\'&&a!=\'1i\')$(2).o(\'1m\',\'1i\')})}})}:3(){e 2},1g:S?3(){e 2.B(3(){$(2).o({\'17\':\'\',N:\'\'})})}:3(){e 2},1f:3(){e 2.B(3(){$(2)[$(2).C()?"n":"l"]()})},j:3(){e 2.1e(\'1Z\')||2.1e(\'1k\')}});3 1j(a){4(d.8)e;d.8=$(\'<p R="\'+a.R+\'"><W></W><p 1c="9"></p><p 1c="j"></p></p>\').1X(I.9).l();4($.F.1a)d.8.1a();d.g=$(\'W\',d.8);d.9=$(\'p.9\',d.8);d.j=$(\'p.j\',d.8)}3 7(a){e $.1d(a,"f-7")}3 19(a){4(7(2).O)w=1T(n,7(2).O);A n();H=!!7(2).H;$(I.9).1R(\'K\',q);q(a)}3 16(){4($.f.r||2==k||(!2.T&&!7(2).J))e;k=2;g=2.T;4(7(2).J){d.g.l();m a=7(2).J.1P(2);4(a.1N||a.1M){d.9.12().P(a)}A{d.9.C(a)}d.9.n()}A 4(7(2).10){m b=g.1L(7(2).10);d.g.C(b.1K()).n();d.9.12();1J(m i=0,M;M=b[i];i++){4(i>0)d.9.P("<1I/>");d.9.P(M)}d.9.1f()}A{d.g.C(g).n();d.9.l()}4(7(2).11&&$(2).j())d.j.C($(2).j().1H(\'1F://\',\'\')).n();A d.j.l();d.8.V(7(2).U);4(7(2).D)d.8.D();19.1E(2,1D)}3 n(){w=L;d.8.n();q()}3 q(c){4($.f.r)e;4(!H&&d.8.1A(":1z")){$(I.9).18(\'K\',q)}4(k==L){$(I.9).18(\'K\',q);e}d.8.Q("t-Y").Q("t-13");m b=d.8[0].14;m a=d.8[0].X;4(c){b=c.1v+7(k).z;a=c.1V+7(k).u;d.8.o({z:b+\'E\',u:a+\'E\'})}m v=t(),h=d.8[0];4(v.x+v.1q<h.14+h.1p){b-=h.1p+20+7(k).z;d.8.o({z:b+\'E\'}).V("t-Y")}4(v.y+v.1l<h.X+h.1n){a-=h.1n+20+7(k).u;d.8.o({u:a+\'E\'}).V("t-13")}}3 t(){e{x:$(G).28(),y:$(G).27(),1q:$(G).26(),1l:$(G).25()}}3 l(a){4($.f.r)e;4(w)24(w);k=L;d.8.l().Q(7(2).U);4(7(2).D)d.8.1g()}$.F.2d=$.F.f})(22);',62,140,'||this|function|if|||settings|parent|body|||||return|tooltip|title|||url|current|hide|var|show|css|div|update|blocked||viewport|top||tID|||left|else|each|html|fixPNG|px|fn|window|track|document|bodyHandler|mousemove|null|part|backgroundImage|delay|append|removeClass|id|IE|tooltipText|extraClass|addClass|h3|offsetTop|right|true|showBody|showURL|empty|bottom|offsetLeft||save|filter|unbind|handle|bgiframe|defaults|class|data|attr|hideWhenEmpty|unfixPNG|false|relative|createHelper|src|cy|position|offsetHeight|extend|offsetWidth|cx|Microsoft|DXImageTransform|block|progid|pageX|navigator|none|RegExp|visible|is|test|png|arguments|apply|http|match|replace|br|for|shift|split|jquery|nodeType|click|call|200|bind|hover|setTimeout|alt|pageY|removeAttr|appendTo|MSIE|href||msie|jQuery|absolute|clearTimeout|height|width|scrollTop|scrollLeft|crop|sizingMethod|enabled|AlphaImageLoader|Tooltip|userAgent|browser'.split('|'),0,{}));
/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-06-22 04:38:37 +0200 (Fr, 22 Jun 2007) $
 * $Rev: 2141 $
 *
 * Version: 1.0b2
 */
(function($){

// store a copy of the core height and width methods
var height = $.fn.height,
    width  = $.fn.width;

$.fn.extend({
	height: function() {
		if ( this[0] == window )
			return self.innerHeight ||
				$.boxModel && document.documentElement.clientHeight || 
				document.body.clientHeight;
		
		if ( this[0] == document )
			return Math.max( document.body.scrollHeight, document.body.offsetHeight );
		
		return height.apply(this, arguments);
	},
	width: function() {
		if ( this[0] == window )
			return self.innerWidth ||
				$.boxModel && document.documentElement.clientWidth ||
				document.body.clientWidth;

		if ( this[0] == document )
			return Math.max( document.body.scrollWidth, document.body.offsetWidth );

		return width.apply(this, arguments);
	},
	innerHeight: function() {
		return this[0] == window || this[0] == document ?
			this.height() :
			this.is(':visible') ?
				this[0].offsetHeight - num(this, 'borderTopWidth') - num(this, 'borderBottomWidth') :
				this.height() + num(this, 'paddingTop') + num(this, 'paddingBottom');
	},
	innerWidth: function() {
		return this[0] == window || this[0] == document ?
			this.width() :
			this.is(':visible') ?
				this[0].offsetWidth - num(this, 'borderLeftWidth') - num(this, 'borderRightWidth') :
				this.width() + num(this, 'paddingLeft') + num(this, 'paddingRight');
	},
	outerHeight: function() {
		return this[0] == window || this[0] == document ?
			this.height() :
			this.is(':visible') ?
				this[0].offsetHeight :
				this.height() + num(this,'borderTopWidth') + num(this, 'borderBottomWidth') + num(this, 'paddingTop') + num(this, 'paddingBottom');
	},
	outerWidth: function() {
		return this[0] == window || this[0] == document ?
			this.width() :
			this.is(':visible') ?
				this[0].offsetWidth :
				this.width() + num(this, 'borderLeftWidth') + num(this, 'borderRightWidth') + num(this, 'paddingLeft') + num(this, 'paddingRight');
	},
	scrollLeft: function(val) {
		if ( val != undefined )
			// set the scroll left
			return this.each(function() {
				if (this == window || this == document)
					window.scrollTo( val, $(window).scrollTop() );
				else
					this.scrollLeft = val;
			});
		
		// return the scroll left offest in pixels
		if ( this[0] == window || this[0] == document )
			return self.pageXOffset ||
				$.boxModel && document.documentElement.scrollLeft ||
				document.body.scrollLeft;
				
		return this[0].scrollLeft;
	},
	scrollTop: function(val) {
		if ( val != undefined )
			// set the scroll top
			return this.each(function() {
				if (this == window || this == document)
					window.scrollTo( $(window).scrollLeft(), val );
				else
					this.scrollTop = val;
			});
		
		// return the scroll top offset in pixels
		if ( this[0] == window || this[0] == document )
			return self.pageYOffset ||
				$.boxModel && document.documentElement.scrollTop ||
				document.body.scrollTop;

		return this[0].scrollTop;
	},
	position: function(options, returnObject) {
		var elem = this[0], parent = elem.parentNode, op = elem.offsetParent,
		    options = $.extend({ margin: false, border: false, padding: false, scroll: false }, options || {}),
			x = elem.offsetLeft,
			y = elem.offsetTop, 
			sl = elem.scrollLeft, 
			st = elem.scrollTop;
			
		// Mozilla and IE do not add the border
		if ($.browser.mozilla || $.browser.msie) {
			// add borders to offset
			x += num(elem, 'borderLeftWidth');
			y += num(elem, 'borderTopWidth');
		}

		if ($.browser.mozilla) {
			do {
				// Mozilla does not add the border for a parent that has overflow set to anything but visible
				if ($.browser.mozilla && parent != elem && $.css(parent, 'overflow') != 'visible') {
					x += num(parent, 'borderLeftWidth');
					y += num(parent, 'borderTopWidth');
				}

				if (parent == op) break; // break if we are already at the offestParent
			} while ((parent = parent.parentNode) && (parent.tagName.toLowerCase() != 'body' || parent.tagName.toLowerCase() != 'html'));
		}
		
		var returnValue = handleOffsetReturn(elem, options, x, y, sl, st);
		
		if (returnObject) { $.extend(returnObject, returnValue); return this; }
		else              { return returnValue; }
	},
	offset: function(options, returnObject) {
		var x = 0, y = 0, sl = 0, st = 0,
		    elem = this[0], parent = this[0], op, parPos, elemPos = $.css(elem, 'position'),
		    mo = $.browser.mozilla, ie = $.browser.msie, sf = $.browser.safari, oa = $.browser.opera,
		    absparent = false, relparent = false, 
		    options = $.extend({ margin: true, border: false, padding: false, scroll: true, lite: false }, options || {});
		
		// Use offsetLite if lite option is true
		if (options.lite) return this.offsetLite(options, returnObject);
		
		if (elem.tagName.toLowerCase() == 'body') {
			// Safari is the only one to get offsetLeft and offsetTop properties of the body "correct"
			// Except they all mess up when the body is positioned absolute or relative
			x = elem.offsetLeft;
			y = elem.offsetTop;
			// Mozilla ignores margin and subtracts border from body element
			if (mo) {
				x += num(elem, 'marginLeft') + (num(elem, 'borderLeftWidth')*2);
				y += num(elem, 'marginTop')  + (num(elem, 'borderTopWidth') *2);
			} else
			// Opera ignores margin
			if (oa) {
				x += num(elem, 'marginLeft');
				y += num(elem, 'marginTop');
			} else
			// IE does not add the border in Standards Mode
			if (ie && jQuery.boxModel) {
				x += num(elem, 'borderLeftWidth');
				y += num(elem, 'borderTopWidth');
			}
		} else {
			do {
				parPos = $.css(parent, 'position');
			
				x += parent.offsetLeft;
				y += parent.offsetTop;

				// Mozilla and IE do not add the border
				if (mo || ie) {
					// add borders to offset
					x += num(parent, 'borderLeftWidth');
					y += num(parent, 'borderTopWidth');

					// Mozilla does not include the border on body if an element isn't positioned absolute and is without an absolute parent
					if (mo && parPos == 'absolute') absparent = true;
					// IE does not include the border on the body if an element is position static and without an absolute or relative parent
					if (ie && parPos == 'relative') relparent = true;
				}

				op = parent.offsetParent;
				if (options.scroll || mo) {
					do {
						if (options.scroll) {
							// get scroll offsets
							sl += parent.scrollLeft;
							st += parent.scrollTop;
						}
				
						// Mozilla does not add the border for a parent that has overflow set to anything but visible
						if (mo && parent != elem && $.css(parent, 'overflow') != 'visible') {
							x += num(parent, 'borderLeftWidth');
							y += num(parent, 'borderTopWidth');
						}
				
						parent = parent.parentNode;
					} while (parent != op);
				}
				parent = op;

				if (parent.tagName.toLowerCase() == 'body' || parent.tagName.toLowerCase() == 'html') {
					// Safari and IE Standards Mode doesn't add the body margin for elments positioned with static or relative
					if ((sf || (ie && $.boxModel)) && elemPos != 'absolute' && elemPos != 'fixed') {
						x += num(parent, 'marginLeft');
						y += num(parent, 'marginTop');
					}
					// Mozilla does not include the border on body if an element isn't positioned absolute and is without an absolute parent
					// IE does not include the border on the body if an element is positioned static and without an absolute or relative parent
					if ( (mo && !absparent && elemPos != 'fixed') || 
					     (ie && elemPos == 'static' && !relparent) ) {
						x += num(parent, 'borderLeftWidth');
						y += num(parent, 'borderTopWidth');
					}
					break; // Exit the loop
				}
			} while (parent);
		}

		var returnValue = handleOffsetReturn(elem, options, x, y, sl, st);

		if (returnObject) { $.extend(returnObject, returnValue); return this; }
		else              { return returnValue; }
	},
	offsetLite: function(options, returnObject) {
		var x = 0, y = 0, sl = 0, st = 0, parent = this[0], op, 
		    options = $.extend({ margin: true, border: false, padding: false, scroll: true }, options || {});
				
		do {
			x += parent.offsetLeft;
			y += parent.offsetTop;

			op = parent.offsetParent;
			if (options.scroll) {
				// get scroll offsets
				do {
					sl += parent.scrollLeft;
					st += parent.scrollTop;
					parent = parent.parentNode;
				} while(parent != op);
			}
			parent = op;
		} while (parent && parent.tagName.toLowerCase() != 'body' && parent.tagName.toLowerCase() != 'html');

		var returnValue = handleOffsetReturn(this[0], options, x, y, sl, st);

		if (returnObject) { $.extend(returnObject, returnValue); return this; }
		else              { return returnValue; }
	}
});

var num = function(el, prop) {
	return parseInt($.css(el.jquery?el[0]:el,prop))||0;
};

var handleOffsetReturn = function(elem, options, x, y, sl, st) {
	if ( !options.margin ) {
		x -= num(elem, 'marginLeft');
		y -= num(elem, 'marginTop');
	}

	// Safari and Opera do not add the border for the element
	if ( options.border && ($.browser.safari || $.browser.opera) ) {
		x += num(elem, 'borderLeftWidth');
		y += num(elem, 'borderTopWidth');
	} else if ( !options.border && !($.browser.safari || $.browser.opera) ) {
		x -= num(elem, 'borderLeftWidth');
		y -= num(elem, 'borderTopWidth');
	}

	if ( options.padding ) {
		x += num(elem, 'paddingLeft');
		y += num(elem, 'paddingTop');
	}
	
	// do not include scroll offset on the element
	if ( options.scroll ) {
		sl -= elem.scrollLeft;
		st -= elem.scrollTop;
	}

	return options.scroll ? { top: y - st, left: x - sl, scrollTop:  st, scrollLeft: sl }
	                      : { top: y, left: x };
};

})(jQuery);

// Função Usada para fazer as máscaras.

//Manipulador de Eventos: addEvent e removeEvent cross-browser
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};
removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};
//Fim do Manipulador de Eventos

function maskInput(f, m) {
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
}


// Função usada para colocar as mascaras e os tooltips.

function pegaTodosOsControlesDoFormulario(maiorDeTodos){
	var filho;
	var nomeTag;
	var nomeClasse;
	var filhoContr;
	
	// Passo por todos os controles.
	$(maiorDeTodos).children().each(function(i){
		filho = $(this);
		nomeTag = filho.attr('tagName');
 	 	if (nomeTag == 'LABEL') {
			nomeClasse = $(filho).attr('class');
			
			filhoContr = filho.children('input,textarea,select');
			if (filhoContr != null) {
				$(filhoContr).tooltip({
				    track: true, 
				    delay: 0, 
				    showURL: false, 
				    showBody: " - ", 
				    opacity: 0.85 
				});
			
			    if (nomeClasse != null) {
				    // Verifica se o campo é do tipo DATA se for coloca uma máscara de data nele.
				    // Formato: dd/mm/yyyy
				    if ((nomeClasse.match('vData') == 'vData')) {
					    maskInput(document.getElementById($(filhoContr).attr('id')),'99/99/9999');
				    }
    				
				    // Verifica se o campo é do tipo TELEFONE se for coloca uma máscara de telefone nele.
				    // Formato: (99) 9999-9999
				    if ((nomeClasse.match('vTelefone') == 'vTelefone')) {
					    maskInput(document.getElementById($(filhoContr).attr('id')),'(99) 9999-9999');
				    }
    				
				    // Verifica se o campo do tipo CEP e se for coloca uma máscara de cep nele.
				    // Formato: 99999-999
				    if ((nomeClasse.match('vCep') == 'vCep')) {
					    maskInput(document.getElementById($(filhoContr).attr('id')),'99999-999');
				    }
			    }
			}
		}
		else {
			// Caso não encontre um LABEL, chama a função novamente para verificar se esse elemento contém um controle label.
			pegaTodosOsControlesDoFormulario(filho);
		}
	});
}

// Funções usadas para atribuir as cores vermelhas de erros aos span dos controles e para validação dos controles.

var error;
var primeiroControle;
function zeraError() {
	error = 0;
	primeiroControle = 0;
}

function pegaTodosParentesDeBaixo(maiorDeTodos){
	var filho;
	var nomeTag;
	var nomeClasse;
	var filhoSpan;
	var filhoContr;
	var filhoContrValor;
	var filhoContrValorTrim;
	var apresentarError = 0;
	
	// Passo por todos os controles.
	$(maiorDeTodos).children().each(function(i){
		filho = $(this);
		nomeTag = filho.attr('tagName');
 	 	if (nomeTag == 'LABEL') {
			nomeClasse = $(filho).attr('class');
			if (nomeClasse != null) {
				filhoSpan = filho.children('span');
				filhoContr = filho.children('input,textarea,select');
				filhoContrValor = filhoContr.val();
				filhoContrValorTrim = $.trim(filhoContrValor);
				
				if (filhoContr != null) {
					// Verifica se é OBRIGATÓRIO e se for obrigatório e tiver vazio grava 1 na variavel 'apresentarError'.
					if ((nomeClasse.match('vObrigatorio') == 'vObrigatorio') && (filhoContrValorTrim == '')) 
						apresentarError = 1;
					
					// Verifica se o campo é do tipo DATA e se for e tiver errada grava 1 na variavel 'apresentarError'.
					// Formato: dd/mm/yyyy
					if ((nomeClasse.match('vData') == 'vData') && (filhoContrValorTrim != '')) {
						var dat = /((([0][1-9]|[12][\\d])|[3][01])[-\/]([0][13578]|[1][02])[-\/][1-9]\d\d\d)|((([0][1-9]|[12][\d])|[3][0])[-\/]([0][13456789]|[1][012])[-\/][1-9]\d\d\d)|(([0][1-9]|[12][\d])[-\/][0][2][-\/][1-9]\d([02468][048]|[13579][26]))|(([0][1-9]|[12][0-8])[-\/][0][2][-\/][1-9]\d\d\d)$/;
						if (!filhoContrValor.match(dat)) 
							apresentarError = 1;
					}
					
					// Verifica se o campo é do tipo TELEFONE e se for e tiver errado grava 1 na variavel 'apresentarError'.
					// Formato: (99) 9999-9999
					if ((nomeClasse.match('vTelefone') == 'vTelefone') && (filhoContrValorTrim != '')) {
						var tel = /^([\(]{1}[0-9]{2}[\)]{1}[ ]{1}[0-9]{4}[\-]{1}[0-9]{4})$/;
						if (!filhoContrValor.match(tel)) 
							apresentarError = 1;
					}
					
					// Verifica se o campo é do tipo EMAIL e se for e tiver errado grava 1 na variavel 'apresentarError'.
					if ((nomeClasse.match('vEmail') == 'vEmail') && (filhoContrValorTrim != '')) {
						var mail = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
						if (!filhoContrValor.match(mail)) 
							apresentarError = 1;
					}
					
					// Verifica se o campo do tipo NÚMERO INTEIRO e se for e tiver errado grava 1 na variavel 'apresentarError'.
					if ((nomeClasse.match('vNumero') == 'vNumero') && (filhoContrValorTrim != '')) {
						var num = /^\d*$/;
						if (!filhoContrValor.match(num)) 
							apresentarError = 1;
					}
					
					// Verifica se o campo do tipo CEP e se for e tiver errado grava 1 na variavel 'apresentarError'.
					// Formato: 99999-999
					if ((nomeClasse.match('vCep') == 'vCep') && (filhoContrValorTrim != '')) {
						var num = /^(\d{5}-\d{3})*$/;
						if (!filhoContrValor.match(num)) 
							apresentarError = 1;
					}
					
					if (apresentarError == 1) {
						
						// Foca no primeiro controle que der erro;
						if (primeiroControle == 0) {
							$(filhoContr).focus();
							primeiroControle = 1;
						}
						
						error = 1;
						//filhoSpan.css('color', 'red');
						//filhoSpan.css('font-weight', 'bold');
						filho.addClass('error');
					}
					else {
						//filhoSpan.css('color', '');
						//filhoSpan.css('font-weight', '');
						filho.removeClass('error');
					}
				}
			}
		}
		else {
			// Caso não encontre um LABEL, chama a função novamente para verificar se esse elemento contém um controle label.
			pegaTodosParentesDeBaixo(filho);
		}
	});
	
	if (error == 1) {
		return false;
	}
	else {
		return true;
	}
}

function validaForm(area){
	zeraError();
	var temError = 0;
	$(area).children().each(function(i){
		if (pegaTodosParentesDeBaixo($(this)) == false) {
			temError = 1;
		}
	});
	
	if (temError == 1) {
		return false;
	}
	else {
		return true;
	}
}

$(function(){
	var IDForm = '#formulario';
	var IDButton = '#btnEnviar';

	pegaTodosOsControlesDoFormulario(IDForm);
	$(IDButton).click(function(){
		return validaForm(IDForm);
	});		
});

$(function(){
	var IDForm = '#indique_validate';
	var IDButton = '#btnIndicar';

	pegaTodosOsControlesDoFormulario(IDForm);
	$(IDButton).click(function(){
		return validaForm(IDForm);
	});		
});